// pages/wallet/index.js
const api = require('../../utils/api.js');
const app = getApp();
Page({
  data: {
    overage: 0, //余额
    ticket: 0,
    deposit_str: null,  //押金
  },
  getData() {
    const that = this;
    wx.setNavigationBarTitle({
      title: '我的钱包'
    })
    api.myWallet(app.globalData.token).then(res => {
      let myData = res.data.data;
      that.setData({
        overage: myData.balance,
        deposit_str: myData.deposit
      })
    });
  },
  // 页面加载
  onLoad: function (options) {
    this.getData();
  },

  // 余额说明
  overageDesc: function () {
    wx.showModal({
      title: "",
      content: "充值余额50.00元+活动扣除余额-100.00元",
      showCancel: false,
      confirmText: "我知道了",
    })
  },
  // 跳转到充值页面
  movetoCharge: function () {
    // 关闭当前页面，跳转到指定页面，返回时将不会回到当前页面
    wx.redirectTo({
      url: '../balance/balance'
    })
  },
  // 用车券
  showTicket: function () {
    wx.showModal({
      title: "",
      content: "你没有用车券了",
      showCancel: false,
      confirmText: "好吧",
    })
  },
  //交押金
  payDeposit: function(){
    wx.redirectTo({
      url: '../payDeposit/payDeposit'
    })
  },
  // 押金退还
  showDeposit: function () {
    const that = this;
    wx.showModal({
      title: "",
      content: "押金会立即退回，退款后，您将不能使用雨伞确认要进行此退款吗？",
      cancelText: "继续使用",
      cancelColor: "#b9dd08",
      confirmText: "押金退款",
      confirmColor: "#ccc",
      success: (res) => {
        if (res.confirm) {
          console.log('用户点击确定');
          api.returnDeposit(app.globalData.token).then(res => {
            console.log(res);
            wx.showToast({
              title: '押金退还成功',
              icon: 'success',
              duration: 2000
            });
            that.getData();
          });
        } else if (res.cancel) {
          console.log('用户点击取消');
        }
      }
    })
  },
  // 关于ofo
  showInvcode: function () {
    wx.showModal({
      title: "ofo共享单车",
      content: "微信服务号：到此一游",
      showCancel: false,
      confirmText: "返回"
    })
  }
})